package middle;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;

public class leetcode189 {
    public static void main(String[] args) {
        /*
            5 1 2 3 4
            5 4 1 2 3
            5 4 3 1 2
            5 4 3 2 1
            1 5 4 3 2
         */
        int[] arr = {1, 2, 3, 4, 5, 6, 7};
        rotateArr(arr,3);
//        System.out.println(Arrays.toString(arr));

        System.out.println(Arrays.toString(arr));

    }

    public static void rotateArr(int[] arr, int k) {
        Queue<Integer> queue = new ArrayDeque<>();
        for (int i = arr.length - 1; i >=0; i--) {
            queue.add(arr[i]);
        }
        System.out.println(queue);
        for (int i = 0; i < k; i++) {
            queue.add(queue.poll());
        }
        System.out.println(queue);
        for (int i = queue.size() - 1; i >= 0; i--) {
            arr[i] = queue.poll();
        }
    }
}
